﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<skags.Models.ProfileViewModel>" %>
<div id="profile">
<%
    string filePath = Request.MapPath("~/Content/users/user_" + Model.Info.ID + ".jpg");
    string thePic;
    if (System.IO.File.Exists(filePath))
    {
        thePic = Url.Content("~/Content/users/user_" + Model.Info.ID + ".jpg");
    } else
    {
        thePic = Url.Content("~/Content/users/unknown.jpg");
    }%>
<img src="<%=thePic%>" id="profile_picture" alt="" />
<div id="profile_info">
<h2><%=Model.Info.UserName%></h2>
<%
    if (Model.PrivacySettings != null)
    {
     %>
<p><b>Nafn:</b> <%=Model.Info.FullName%></p>
<%
        if (Model.PrivacySettings.ShowEmail)
        {
            Response.Write("<p><b>Netfang:</b> ");
            Response.Write(Model.Info.Email);
            Response.Write("</p>");
        }

        if (Model.PrivacySettings.ShowAddress)
        {
            if (Model.PrivacySettings.ShowAddress)
            {
                Response.Write("<p><b>Heimili:</b> ");
                Response.Write(Model.Info.Address + ", " + Model.Info.ZipCode);
                Response.Write("</p>");
            }
        }
        
        if (!String.IsNullOrEmpty(Model.Info.FacebookUrl))
        {
            Response.Write("<p><b>Facebook:</b> <a href=\"" + Model.Info.FacebookUrl + "\">" + Model.Info.FacebookUrl + "</a></p>");
        }
%>
   <p><b>Síðast innskráður:</b> <%=String.Format("{0:g}", Model.LastLogin)%></p>
   <%
        if (Model.PrivacySettings.ShowNumOfChildren)
        {
            Response.Write("<p><b>Fjöldi barna:</b> ");
            Response.Write(Model.Child.Count());
            Response.Write("</p>");
        }

        if (!String.IsNullOrEmpty(Model.Info.Description))
        {
            Response.Write("<p id=\"profile_lysing\">");
            Response.Write("<h3>Lýsing:</h3> ");
            Response.Write("<i>" + Model.Info.Description + "</i>");
            Response.Write("</p>");
        }
%>
</div>
<%
        if (Model.PrivacySettings.ShowChildrenNames)
        {
%>
<div id="profile_children">
<%
            if (Model.Child.Count() == 0)
                Response.Write("Þú átt engin börn.");
            else
            {  %>
              <h3>Börn:</h3>
                   <table>
                   <tr>
                   <th>Nafn</th>
                   <th>Aldur</th>
                   <th>Lýsing</th>
                   </tr>
                       <% foreach (var s in Model.Child)
                        {
                            var age = (DateTime.Now.Year) - (s.BirthDate.Year);%>
                        <tr>
                                <td>
                                   <%: s.Name%>
                                </td>
                                <td><%: age %>&nbsp; <%if (age == 1){%>árs<%}else{%> ára<%}%></td>
                                <td>
                                     <%: s.Description%>
                                </td>
                        </tr>
                 
                        <% }%>

                  </table> 
                
           <% }
%>
</div>
<%
        }
    }
    else
{
  Response.Write("Notandi hefur ekki virkt sjáanleika prófíls.");
}
%>
</div>